package com.wangjiyuan.giftshuo.base;

import android.app.Application;


import com.wangjiyuan.giftshuo.bean. cache.DaoMaster;
import com.wangjiyuan.giftshuo.bean.cache.DaoSession;

import org.greenrobot.greendao.database.Database;

/**
 * Created by QXL on 2016/11/16.
 */

public class App extends Application {
    public static App app;

    private DaoSession daoSession;
    private Database db;

    @Override
    public void onCreate() {
        super.onCreate();
        app = this;
        NewDataBase();
    }

    private void NewDataBase() {
        //其实是创建了一个SqliteOpenhelper
        DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "lws.db");
        //创建数据库
        db = helper.getWritableDb();
        //得到数据库操作类
        daoSession = new DaoMaster(db).newSession();

    }

    public DaoSession getDaoSession() {
        return daoSession;
    }

    public Database getDb() {
        return db;
    }
}
